#include "FightFailedScene.h"
#include "../../../model/proxy/FightProxy.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../model/vo/DataVO.h"
#include "../../../model/static/StaticRole.h"

FightFailedScene::FightFailedScene()
	:mSelfAttack(NULL),mSelfDefense(NULL),mSelfLife(NULL),
	mBossIcon(NULL),mOtherAttack(NULL),mOtherDefense(NULL),mOtherLife(NULL)
{

}

FightFailedScene::~FightFailedScene()
{
	CC_SAFE_RELEASE(mSelfAttack);
	CC_SAFE_RELEASE(mSelfDefense);
	CC_SAFE_RELEASE(mSelfLife);
	CC_SAFE_RELEASE(mOtherAttack);
	CC_SAFE_RELEASE(mOtherDefense);
	CC_SAFE_RELEASE(mOtherLife);
}

cocos2d::extension::SEL_CCControlHandler FightFailedScene::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onReturnBtnClick", FightFailedScene::onReturnBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onReturnListBtnClick", FightFailedScene::onReturnListBtnClick);
	return NULL;
}

bool FightFailedScene::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mSelfAttack", CCLabelTTF *, this->mSelfAttack);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mSelfDefense", CCLabelTTF *, this->mSelfDefense);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mSelfLife", CCLabelTTF *, this->mSelfLife);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mOtherAttack", CCLabelTTF *, this->mOtherAttack);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mOtherDefense", CCLabelTTF *, this->mOtherDefense);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mOtherLife", CCLabelTTF *, this->mOtherLife);

	return NULL;
}

void FightFailedScene::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{
	mBossIcon = BossIcon::create();
	mBossIcon->setPosition(ccp(160, 400));
	addChild(mBossIcon);
}

bool FightFailedScene::init()
{
	return true;
}

void FightFailedScene::onEnter()
{
	State::onEnter();
	refresh();
}

void FightFailedScene::onExit()
{
	State::onExit();
}

void FightFailedScene::refresh()
{
	int bossID = FightProxy::getSingletonPtr()->bossID;
	UserVO& userVO = UserProxy::getSingletonPtr()->userVO;
	BossInfo* bossInfo = StaticRole::getSingletonPtr()->getBossInfo(bossID);
	mSelfAttack->setString(fcs("%d", userVO.atkMin));
	mSelfDefense->setString(fcs("%d", userVO.defMin));
	mSelfLife->setString(fcs("%d", userVO.life));
	mOtherAttack->setString(fcs("%d--%d", bossInfo->atk_min, bossInfo->atk_max));
	mOtherDefense->setString(fcs("%d", bossInfo->def));
	mOtherLife->setString(fcs("%d", bossInfo->life));
	mBossIcon->bossID = bossID;
	mBossIcon->setIcon();
}

void FightFailedScene::onReturnBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	Framework::getSingletonPtr()->changeState("DungeonsScene");
}

void FightFailedScene::onReturnListBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	Framework::getSingletonPtr()->changeState("DungeonsListScene");
}
